import {userInfoStore} from '@/stores/counter'
import per from "@/directives/per.js";


export function hasPermission(allowRoleList) {
    // 1.获取当前自己的角色
    // 2.所有允许的角色
    const info = userInfoStore()
    if (allowRoleList.indexOf(info.userRole) !== -1) {
        return true;
    }
    return false;
}

export function hasPermission2(name, method) {
    // 1.获取当前自己的角色
    // 2.所有允许的角色
    const info = userInfoStore()
    const methodList = info.userPermission[name];
    if (!methodList) {
        return false;
    }
    if (methodList.indexOf(method) !== -1) {
        return true
    }
    return false;
}

export function hasButton(permissions) {
    for (let permission of permissions) {
        if (hasPermission2(permission["name"], permission["method"])) {
            return true
        } else {
            continue
        }
    }
    return false
}